package com.mf.controller;


import com.mf.groups.GroupsAddInterface;
import com.mf.groups.GroupsUpdateInterface;
import com.mf.result.Result;
import com.mf.utils.UtilConverter;
import com.mf.entity.req.publicReq.ReqPublicIds;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.mf.entity.dto.DtoRiveDetail;
import com.mf.entity.req.ReqRiveDetail;
import com.mf.service.ServiceRiveDetail;
import com.mf.entity.req.search.SearchReqRiveDetail;

import java.util.List;

/**
 * 撕碎投入明细
 */
@RestController
@RequestMapping("rivedetail")
@Tag(name = "撕碎投入明细")
public class ControllerRiveDetail {
    @Resource
    private ServiceRiveDetail serviceriveDetail;

    @Operation(summary = "分页列表查询")
    @PostMapping("/page")
    public Result<Page<DtoRiveDetail>> findPage(@Validated @RequestBody SearchReqRiveDetail searchReqRiveDetail) {
        return Result.success(serviceriveDetail.findPageByParams(searchReqRiveDetail));
    }

    @Operation(summary = "列表查询")
    @PostMapping("/list")
    public Result<List<DtoRiveDetail>> list(@Validated @RequestBody SearchReqRiveDetail searchReqRiveDetail) {
        return Result.success(serviceriveDetail.findListByParams(searchReqRiveDetail));
    }

    @Operation(summary = "保存")
    @PostMapping("/save/{riveId}/{sourceId}/{workSource}")
    public Result<Void> save(@Validated @RequestBody ReqPublicIds<Integer> detailIds, @PathVariable Integer riveId,
                             @PathVariable Integer sourceId,
                             @PathVariable Integer workSource) {
        serviceriveDetail.saveDetail(detailIds.getIds(), riveId, sourceId, workSource);
        return Result.success();
    }


    @Operation(summary = "删除")
    @PostMapping("/delete/{riveId}/{id}")
    public Result<Void> delete(@PathVariable Integer riveId, @PathVariable("id") Integer id) {
        serviceriveDetail.removeDetailById(riveId, id);
        return Result.success();
    }

}
